﻿//选择按钮组插件
Vue.component('select-btns-component', {
    template: '<div class="btn-gards"> <div class="btn-row l_3"><a @click="select_money(item)" v-bind:class="{\'active\':this.buy_money==item}" v-if="item!=-1"  v-for="item in btns">{!item!}元</a></div></div>',
    data: function () {
        return {
            buy_money: 0,//购买金额
            btns: null,
        }
    },
    events: {
        'select_btns_init': function (msg) {
            this.btns=msg.btns;
            this.buy_money=msg.btns[0];
        },
    },
    methods:{
        change:function(e){//输入框改变
            var val=parseFloat(e.target.value);//字符串转浮点数
            if(val){
                this.select_money(val);
            }
        },
        select_money:function(money){
            //选择金额
            this.buy_change(money)
        },
        buy_change:function (money){
            money = parseFloat(money);
            this.buy_money = money;
            this.$dispatch('select_money_change', { money: money })
        },
        change: function (t) {
            var money = parseFloat(t.target.value);
            if (money > 0) {
                this.buy_money = money;
                this.$dispatch('select_money_change', {money: money});
            } else {
                this.buy_money = this.btns[0];
                this.$dispatch('select_money_change', {money: this.btns[0]});
            }
        },
        blur: function (t) {
            var money = parseFloat(t.target.value);
            if (money > 0) {
                this.buy_money = money;
                this.$dispatch('select_money_change', { money: money });
            } else {
                this.buy_money = this.btns[0];
                this.$dispatch('select_money_change', {money: this.btns[0]});
            }
        },
    }
});
// 选择银行按钮
Vue.component('select-bank-btns-component', {
    template: '<div class="tab"><a class="btn" @click="select_bank(item)" v-bind:class="{\'active\':this.cz_bank.value==item.value}" v-if="item!=-1"  v-for="item in banks"><i style="font-size:30px;"><svg class="icon" style="width:1em;" aria-hidden="true"><use xlink:href="#{!item.icon!}"></use></svg></i>&nbsp;{!item.name!}</a></div>',
    data: function () {
        return {
            cz_bank:null,//选中银行
            banks: null,
        }
    },
    events: {
        'select_banks_init': function (msg) {
            this.banks = msg.banks;
            this.cz_bank= msg.default_bank;
        },
    },
    methods:{
        select_bank:function(bank){
            //选择银行
            this.buy_change(bank)
        },
        buy_change:function (bank){
            this.cz_bank = bank;
            this.$dispatch('select_bank_change', { bank: bank })
        }
    }
});
